Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timeline: Fix HTML source processing, load WebChannel from Qt resource system #3702

Merged
merged 4 commits into from
Oct 16, 2020

Conversation

ferdnyc
Copy link
Contributor

@ferdnyc ferdnyc commented Aug 31, 2020

  • Don't leave file handles dangling open, when reading HTML file
  • Change mixin placeholder to an HTML comment, so the source is valid with or without replacement

Fixes this error spit out when Travis ran the unit tests:

logger:ERROR /home/travis/build/OpenShot/openshot-qt/src/windows/views/timeline_mixins.py:124:
 ResourceWarning: unclosed file
 <_io.TextIOWrapper name='/home/travis/build/OpenShot/openshot-qt/src/timeline/index.html' mode='r' encoding='utf-8'>
logger:ERROR   html = open(self.html_path, 'r', encoding='utf-8').read()

Also fixes a few setInterval() calls we were making using float arguments, leading to:

preview_thread:INFO initPlayer
logger:ERROR /home/travis/build/OpenShot/openshot-qt/src/windows/main_window.py:2787:
 DeprecationWarning: an integer is required (got type float).
  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
logger:ERROR   self.auto_save_timer.setInterval(s.get("autosave-interval") * 1000 * 60)
  • Added a clever trick I found somewhere for handling qwebchannel.js: That file is automatically present in Qt builds that support it via the Qt resource system. QtWebEnginePage supports accessing Qt resources from HTML as qrc: URLs. So instead of keeping qwebchannel.js on the filesystem and conditionally inserting code to load it, we can just place a <script> tag in the HTML that loads the source as qrc:/qtwebchannel/qwebchannel.js. If the code isn't running in a QtWebEngine process, that URL will be invalid and the script tag will be silently ignored.

- Don't leave file handles dangling open, when reading HTML file
- Change mixin placeholder to an HTML comment, so the source is
  valid with or without replacement
@ferdnyc ferdnyc changed the title timeline: Fix HTML source processing timeline: Fix HTML source processing, load WebChannel from Qt resource system Aug 31, 2020
@ferdnyc ferdnyc added the timeline An issue or PR involving the HTML/JS/CSS timeline implementation label Sep 8, 2020
@jonoomph
Copy link
Member

Nice! LGTM

@jonoomph jonoomph merged commit 2b53663 into OpenShot:develop Oct 16, 2020
@ferdnyc ferdnyc deleted the html-processing branch January 7, 2022 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
timeline An issue or PR involving the HTML/JS/CSS timeline implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants